<template>
	<view class="page">
		<up-navbar :title="tite" :autoBack="true" safeAreaInsetTop placeholder> </up-navbar>
		<view>
			<view style="width: 90%; margin: 0 auto; line-height: 100rpx;"><text style="color: #999999;">基本信息</text>
			</view>
		</view>
		<view style="line-height: 100rpx; background-color: #fff;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between; ">
				<view><text style="">姓名:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">

					<input type="text" v-model="form.nickname" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />


				</view>
			</view>
		</view>
		<view style="line-height: 100rpx; background-color: #fff; margin-top: 2rpx;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between;">
				<view><text style="">账号:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">
					<!-- <up-input
					    placeholder="请输入内容"
					    border="none"
					    v-model="value"
					    :customStyle="meirong"
					  ></up-input> -->
					<input type="text" v-model="form.username" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />
				</view>
			</view>
		</view>
		<view style="line-height: 100rpx; background-color: #fff; margin-top: 2rpx;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between;">
				<view><text style="">密码:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">
					<input type="password" v-model="form.password" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />

				</view>
			</view>
		</view>

		
		<view style="line-height: 100rpx; background-color: #fff; margin-top: 2rpx;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between;">
				<view><text style="">联系电话:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">
					<input type="text" v-model="form.mobile" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />

				</view>
			</view>
		</view>
		<view style="line-height: 100rpx; background-color: #fff; margin-top: 2rpx;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between;">
				<view><text style="">个人简介:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">
					<input type="text" v-model="form.desc" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />

				</view>
			</view>
		</view>
		
		<view style="line-height: 100rpx; background-color: #fff; margin-top: 2rpx;">
			<view style="width: 90%; margin: 0 auto;  display: flex; justify-content: space-between;">
				<view><text style="">地址:</text></view>
				<view style="display: flex;align-items:center;justify-content:center;">
					<input type="text" v-model="form.full_address" placeholder="请输入" class="fsafaf" />
					<image class="icon1" src="/static/Frame@2x.png" alt="" />
		
				</view>
			</view>
		</view>

		<view style="height: 300rpx; background-color: #fff; margin-top: 2rpx; ">
			<view style="width: 90%; margin: 0 auto;padding-top: 200rpx;  ">
				<view><up-button class="custom-style" shape="circle" color="#FF6A04" text="保存"
						@click="baocun"></up-button></view>

			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					sale_id:'',
					username: '',
					nickname:'',
					password: '',
					mobile: '',
					full_address: '',
					desc:'',
				},

				value: '',
				tite:'',
				

			}
		},


		onLoad(options) {
			console.log(options)
			var data = JSON.parse(decodeURIComponent(options.options))
			
			this.form.sale_id=data.id
			console.log(this.form.sale_id)
			if(data.id!=null){
				this.tite='编辑销售'
			}else{
				this.tite='添加销售'
			}
			if(this.form.sale_id!=null){
				this.fenhong()
			}
		},

		methods: {
			fenhong() {
				
			
				
				this.$request({
					url: '/api/User/getMySaleDetail',
					header: "application/x-www-form-urlencoded",
					data: {
						sale_id: this.form.sale_id,
					
					}
				}).then(res => {
					if (res.code == 1) {
						console.log(res)
						this.form.desc=res.data.desc
						this.form.full_address=res.data.full_address
						this.form.mobile=res.data.mobile
						this.form.nickname=res.data.nickname
						this.form.username=res.data.username
						this.form.sale_id=res.data.id
					} else {
			
			
					}
				})
			
			},


			baocun() {
				var data={}
				if (!this.form.username) {
					return uni.showToast({
						   icon: 'none',
						    title:'填写账号',			
						    duration:2000		  
						})
				}
				if (!this.form.password) {
					return uni.showToast({
						   icon: 'none',
						    title:'填写密码',			
						    duration:2000		  
						})
				}
				if (!this.form.nickname) {
					return uni.showToast({
						   icon: 'none',
						    title:'填写姓名',			
						    duration:2000		  
						})
				}
				
				if (!this.form.mobile) {
					let reg = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$/;
					if (!reg.test(this.form.mobile)) {
						uni.showToast({
							icon: 'none',
							title: '请输入正确的电话'
						})
						this.form.mobile = '';
						return false;
					}	
					return uni.showToast({
						   icon: 'none',
						    title:'填写手机号',			
						    duration:2000		  
						})
				}
				if (!this.form.full_address) {
					return uni.showToast({
						   icon: 'none',
						    title:'填写详细地址',			
						    duration:2000		  
						})
				}
				
				if(this.form.sale_id!=null){
						data={
							sale_id:this.form.sale_id,
							username: this.form.username,
							nickname:this.form.nickname,
							password: this.form.password,
							mobile: this.form.mobile,
							full_address: this.form.full_address,
							desc:this.form.desc,
						}
					}else{
						data={
							username: this.form.username,
							nickname:this.form.nickname,
							password: this.form.password,
							mobile: this.form.mobile,
							full_address: this.form.full_address,
							desc:this.form.desc,
						}
					}
				console.log(this.form.sale_id)
				this.$request({
					url: '/api/User/saveMySaleInfo',
					header: "application/x-www-form-urlencoded",
					data: data
				}).then(res => {
					if (res.code == 1) {
						console.log(res)
						
						uni.showToast({
						   
						    title:'成功',			//标题
						    duration:2000		  //显示时间
						})
						setTimeout(() => {
						  uni.navigateBack({
						    delta:1
						  });
						}, 600);
						
						// this.neirong=res.data
					} else {
						uni.showToast({
						   icon: 'none',
						    title:res.msg,			//标题
						    duration:2000		  //显示时间
						})	
							
					}
				})
				
				console.log(this.form)
			}
		}
	}
</script>

<style>
	.sel-scroll-view-item-true {
		background-color: #FFF6EE;
		border-radius: 10rpx;
		padding: 20rpx;
		color: #FF9839;
		margin: 10rpx;
		border: 2rpx solid #FF9839;
	}

	.fsafaf {
		text-align: right;
		/* // 重要是这个属性，设置光标的位置，ltr时是鼠标光标在右侧，rtl时是鼠标光标在左侧 */
		direction: ltr;
	}

	.page {
		background: #F8F8F8;
	}

	.linglein_meir {
		background-color: #F2F2F2;
		border-radius: 10rpx;
		padding: 20rpx;
		color: #999999;
		margin: 10rpx;
	}

	.linglein {
		/* width: 30%; */
		/* padding: 10rpx;
		line-height: 80rpx; */
	}

	.icon1 {
		width: 50rpx;
		height: 50rpx;
	}
</style>